﻿using DocumentFormat.OpenXml.InkML;
using Magicodes.ExporterAndImporter.Excel.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NP.BPMReportPlatform.AuthorizationProcessesManager.Dtos;
using NP.BPMReportPlatform.MaterialMasterData.Dtos;
using NP.BPMReportPlatform.RecurringJobs;
using NP.BPMReportPlatform.YCLWLJGZSYC.Dto;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Volo.Abp.Application.Dtos;

namespace NP.BPMReportPlatform.YCLWLJGZSYC
{
    /// <summary>
    /// 原材料未来价格指数预测
    /// </summary>
    //[Authorize]
    [ApiController]
    [Route("api/YCLWLJGZSYC")]
    public class YCLWLJGZSYCController : BPMReportPlatformController
    {
        private readonly IYCLWLJGZSYCRecurringJob _recurringJob;
        private readonly IYCLWLJGZSYCService _service;
        public YCLWLJGZSYCController(IYCLWLJGZSYCRecurringJob recurringJob,
            IYCLWLJGZSYCService service)
        {
            _recurringJob = recurringJob;
            _service = service;
        }

        /// <summary>
        /// 分页获取数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("GetPageList")]
        public async Task<PagedResultDto<YCLWLJGZSYCOutput>> GetPageList([FromBody] YCLWLJGZSYCInput input)
        {
            return await _service.GetPageList(input);
        }
        /// <summary>
        /// 导出数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("ExportData")]
        public async Task<FileContentResult> ExportData([FromBody] YCLWLJGZSYCInput input)
        {
            var data = await _service.ExportData(input);
            var ms = new MemoryStream();
            data.Write(ms);
            data.Close();
            return File(ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        }

        /// <summary>
        /// 获取详情数据
        /// </summary>
        /// <param name="instanceNumber"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetDetail")]
        public async Task<YCLWLJGZSYCDetailData> GetDetail(string instanceNumber)
        {
            return await _service.GetDetailData(instanceNumber);
        }

        /// <summary>
        /// 未提交人员提醒接口
        /// </summary>
        /// <returns></returns>
        [HttpPost("UnSubmitJob")]
        public async Task UnSubmitJob()
        {
            await _recurringJob.SendEmailForNoticeInstanceNotSubmit();
        }

        /// <summary>
        /// 未审批人员提醒接口
        /// </summary>
        /// <returns></returns>
        [HttpPost("ProcessingJob")]
        public async Task ProcessingJob()
        {
            await _recurringJob.SendEmailForNoticeInstanceProcessing();
        }

        /// <summary>
        /// 修复因为业务扩展，新增字段导致的部分表数据缺失
        /// </summary>
        [HttpPost("FixData")]
        public void FixData()
        {
            _service.FixData();
        }
    }
}
